import type { ItemType } from 'ant-design-vue';

/**
 * 过滤菜单
 *
 * @param menus 菜单数组
 */
export function filterMenus(menus: Menu[]) {
  return menus.filter(menu => !menu.hidden);
}

/**
 * 转换界面菜单数据
 *
 * @param menus 菜单列表
 */
export function convertUiMenus(menus: Menu[]): ItemType[] {
  return menus
    .filter(menu => !menu.hidden)
    .map(menu => {
      return {
        icon: menu.icon,
        label: menu.name,
        title: menu.name,
        key: menu.id,
        reportMenu: menu.reportMenu,
        reportId: menu.reportId,
        type: menu.type,
        externalId: menu.externalId,
        children: menu.children?.length ? convertUiMenus(menu.children) : undefined,
      } as any;
    });
}
